package txthandler;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class Handle{
	public static int gwc(String s)
	{
	int length = 0;
	for(int i = 0; i < s.length(); i++)
	{
	int ascii = Character.codePointAt(s, i);
	if(ascii >= 0 && ascii <=255)
	length++;
	else
	length += 2;
	}
	return length;
	}
	public static void main(String[] args) throws IOException {
			FileReader fr;
			try (Scanner sc = new Scanner(System.in)){	
				File file = new File("/Users/swk/Desktop/test/test1.txt");
			    FileWriter writer = new FileWriter(file, true);
				fr = new FileReader("/Users/swk/Desktop/test/test.txt");		
				char[] ch = new char[1024];
			    int len=0;
			    int j=-1;
			    String str ="" ;
				while ((len=fr.read(ch))!=-1) {
					String tempt = new String(ch,0,len);
					str=tempt;
				}
				String tempt ="";
				Double t=Math.floor(gwc(str)/14);
				for (int i=0;i<t;i++) {
			    j+=1;j=j%2;tempt=str.substring(7*i,7*i+7);
				if(j==1) {System.out.println(tempt+"。");writer.write(tempt+"。\r\n");}
				else if(j==0) {System.out.print(tempt+",");writer.write(tempt+"，");}
				}
				System.out.println("......");writer.write("......");
			    writer.close();
			      
			         
				
				
				//下面是查找模块
				System.out.println("----------------------------------------");
				System.out.println("输入要查找的字符：");
				String se = sc.next();
                int nu1 = se.length();
                int nu2 = 0;
                int nu3 = 0;
                for (int i=0;i<str.length();i++) {
                	for (int k=0;k<nu1;k++) {
                	if(Character.codePointAt(str, i+k)==Character.codePointAt(se, k)) {nu2+=1;}
                	if(nu2==nu1) {nu3=nu3+1;}
                	}
                	nu2 = 0;
                }
                System.out.println(se+"出现的次数为"+nu3+"次");
                System.out.println("----------------------------------------");
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
	}

